let myaxios = {
    get(url) { 
        let promise = new Promise((resolve, reject) => { 
            let xml = new XMLHttpRequest()
            xml.open('GET', url, true)
            xml.send()
            xml.onreadystatechange = () => { 
                if (xml.readyState === 4) {
                    if (xml.status >= 200 && xml.status < 300 || xml.status === 304) {
                        resolve(xml.responseText)
                    } else {
                        reject('请求错误',xml)
                    }
                }
            }
            time(xml,reject)
        }) 
        return promise
    },
    post(url, obj) { 
        let promise = new Promise((resolve, reject) => { 
            let xml = new XMLHttpRequest()
            xml.open('POST', url, true)
            xml.setRequestHeader("Content-type","application/x-www-form-urlencoded");
            xml.send(paramsobj(obj))
            xml.onreadystatechange = () => { 
                if (xml.readyState === 4) { 
                    if (xml.status >= 200 && xml.status < 300 || xml.status === 304) {
                        resolve(xml.responseText)
                    } else { 
                        reject('请求错误，请仔细检查url地址',xml)
                    }
                }
            }
            time(xml,reject)
        })
        return promise
    }
}

function paramsobj(obj) { 
    let arr = []
    for (const key in obj) {
        arr.push(`${encodeURI(key)} = ${encodeURI(obj[key])}`)
    }
    return arr.join('&')
}

function time(obj,reject) { 
    let timers = setTimeout(() => { 
        reject('请求超时')
        // 最后一步再中断请求
        obj.abort()
        clearTimeout(timers)
    }, 3000)
    return timers
}